package validate

import (
	"github.com/go-playground/validator/v10"
	"go-project/dto/requrest"
	"go-project/models"
)

func UserNameValidate(field validator.FieldLevel) bool {
	userModel := &models.Admin{}
	username := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.AdminUpdateRequest)
		id = request.AdminId
	}
	if userModel.CheckUsernameExist(username, id) {
		return false
	}
	return true
}
func UserEmailValidate(field validator.FieldLevel) bool {
	userModel := &models.Admin{}
	email := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.AdminUpdateRequest)
		id = request.AdminId
	}
	if userModel.CheckEmailExist(email, id) {
		return false
	}
	return true
}

func UserPhoneValidate(field validator.FieldLevel) bool {
	userModel := &models.Admin{}
	phone := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.AdminUpdateRequest)
		id = request.AdminId
	}
	if userModel.CheckPhoneExist(phone, id) {
		return false
	}
	return true
}
